import { computed, onMounted, onUnmounted, reactive, toRefs } from "vue";

interface CountDataInt {
    count: number,
    dbCount: number
}

export function useCounter() {
    /* 计数器 */
    const countData: CountDataInt = reactive({
        count: 0,
        dbCount: computed(() => countData.count * 2),
    });

    let timer;

    onMounted(() => {
        timer = setInterval(() => {
            countData.count++;
        }, 1000);
    });

    onUnmounted(() => {
        clearInterval(timer);
    });

    return toRefs(countData);
}